import java.applet.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;


public class GraphApp extends JPanel implements ActionListener {

  JPanel graphCalcPanel = new JPanel();
  Label lblNumOne = new Label("Enter Number A:");
  TextField txtNumOne = new TextField(20);
  Label lblNumTwo = new Label("Enter Number B:");
  TextField txtNumTwo = new TextField(5);
  Label lblNumThree = new Label("Enter Number C:");
  TextField txtNumThree = new TextField(5);
  Button btnCalc = new Button("Calculate");
  Button btnClear = new Button("Clear");
  Label lblAnsOne = new Label("Answer A: ");
  Label lblAnsTwo = new Label("Answer B: ");
  Label lblParabolaAns = new Label("Parabola State: ");
  Label lblTotalVertex = new Label("Vertex: ");
  Button btnGraph = new Button("Graph It!");
  Graph plotted = new Graph();

  boolean filledVertex = false;
  int x = 0, y = 0;
  int [][] plotMe = new int[1][2];

  public GraphApp() {
    this.setLayout(null);
    this.setSize(520, 320);

    //GUI BOUNDS//
    lblNumOne.setBounds(0,5,95,10);
    txtNumOne.setBounds(95,0,95,20);
    lblNumTwo.setBounds(0,30,95,10);
    txtNumTwo.setBounds(95,25,95,22);
    lblNumThree.setBounds(0,55,95,10);
    txtNumThree.setBounds(95,50,95,22);
    btnCalc.setBounds(10,80,60,25);
    btnClear.setBounds(90,80,60,25);
    lblAnsOne.setBounds(0,120,85,10);
    lblAnsTwo.setBounds(100,120,85,10);
    lblParabolaAns.setBounds(0,140,110,20);
    lblTotalVertex.setBounds(0,160,110,20);
    btnGraph.setBounds(0,185,60,25);
    //END BOUNDS//

    //Adding features to panel
    this.add(lblNumOne);
    this.add(txtNumOne);

    this.add(lblNumTwo);
    this.add(txtNumTwo);

    this.add(lblNumThree);
    this.add(txtNumThree);

    this.add(btnCalc);
    this.add(btnClear);
    this.add(btnGraph);

    this.add(lblAnsOne);
    this.add(lblAnsTwo);

    this.add(lblParabolaAns);
    this.add(lblTotalVertex);

    btnCalc.addActionListener(this);
    btnClear.addActionListener(this);
    btnGraph.addActionListener(this);


  }

  public void actionPerformed(ActionEvent x) {

  }

  public void paint(Graphics g) {
    int gridWidth = 300;
    int gridHeight = 300;
    int gridStartX = 200;
    int gridStartY = 10;

    int[][] gCPA = new int[4][2];
    gCPA[0][0] = gridStartX;
    gCPA[0][1] = gridStartY;
    gCPA[1][0] = gridStartX;
    gCPA[1][1] = gridStartY + gridWidth;
    gCPA[2][0] = gridStartX + gridHeight;
    gCPA[2][1] = gridStartY + gridWidth;
    gCPA[3][0] = gridStartX + gridHeight;
    gCPA[3][1] = gridStartY;

    g.setColor(Color.gray);

    g.drawRect(gridStartX,gridStartY,gridWidth,gridHeight);

    for(int plotX = 0; plotX < 4; plotX++) {
      for(int plotY = 0; plotY < 4; plotY++) {
        g.drawOval(gCPA[plotX][0]-5,gCPA[plotX][1]-5,10,10);
      }//end for
    }//end for

    int cellInterval = 12;
    int rowNum = gridHeight / cellInterval;
    int rowModifier = 0;

    for (int r = 0; r < rowNum; r++) {
      rowModifier = rowModifier + cellInterval;
      g.drawLine(gCPA[0][0],gCPA[0][1] + rowModifier,gCPA[3][0],gCPA[3][1] + rowModifier);
      g.drawLine(gCPA[0][0] + rowModifier,gCPA[0][1],gCPA[1][0] + rowModifier,gCPA[1][1]);
    }//end for

    int centerX = (((gridWidth / 2) + gCPA[0][0]) + 1);
    int centerY = (((gridHeight / 2) + gCPA[0][1]) + 1);

    String testString = centerX + ", " + centerY;

    g.fillOval(centerX,centerY,10,10);
    g.drawString(testString,10,258);

    if (filledVertex) {

      plotMe[0][0] = x;
      plotMe[0][1] = y;
      int plotX = 0;
      int plotY = 0;

      if (x < 0) {
        plotX = (centerX + (plotMe[0][0] * cellInterval));
      }//end if
      else if (x > 0) {
        plotX = (centerX - (plotMe[0][0] * cellInterval));
      }//end elseif

      if (y < 0) {
        plotY = (centerY - (plotMe[0][1] * cellInterval));
      }//end if
      else if (y > 0) {
        plotY = (centerY + (plotMe[0][1] * cellInterval));
      }//end elseif

      g.drawOval(plotX,plotY,10,10);
    }//end if

  }
}




/*
import java.applet.*;
import java.awt.*;
import java.awt.event.*;

public class GraphApp extends Applet implements ActionListener
{
               	Label lblNumOne = new Label("Enter Number A:");
                TextField txtNumOne = new TextField(20);
                Label lblNumTwo = new Label("Enter Number B:");
                TextField txtNumTwo = new TextField(5);
                Label lblNumThree = new Label("Enter Number C:");
                TextField txtNumThree = new TextField(5);
                Button btnCalc = new Button("Calculate");
                Button btnClear = new Button("Clear");
                Label lblAnsOne = new Label("Answer A: ");
                Label lblAnsTwo = new Label("Answer B: ");
                Label lblParabolaAns = new Label("Parabola State: ");
                Label lblTotalVertex = new Label("Vertex: ");
                Button btnGraph = new Button("Graph It!");

                boolean filledVertex = false;
                int x = 0, y = 0;
                int [][] plotMe = new int[1][2];

                public void init()
                {
					setLayout(null);
					setSize(520,320);

					//GUI BOUNDS//
					lblNumOne.setBounds(0,5,95,10);
					txtNumOne.setBounds(95,0,95,20);
					lblNumTwo.setBounds(0,30,95,10);
					txtNumTwo.setBounds(95,25,95,22);
					lblNumThree.setBounds(0,55,95,10);
					txtNumThree.setBounds(95,50,95,22);
					btnCalc.setBounds(10,80,60,25);
					btnClear.setBounds(90,80,60,25);
					lblAnsOne.setBounds(0,120,85,10);
					lblAnsTwo.setBounds(100,120,85,10);
					lblParabolaAns.setBounds(0,140,110,20);
					lblTotalVertex.setBounds(0,160,110,20);
					btnGraph.setBounds(0,185,60,25);
					//END BOUNDS//

                    add(lblNumOne);
                    add(txtNumOne);

                    add(lblNumTwo);
                    add(txtNumTwo);

                    add(lblNumThree);
                    add(txtNumThree);

                    add(btnCalc);
                    add(btnClear);
                    add(btnGraph);

                    add(lblAnsOne);
                    add(lblAnsTwo);

                    add(lblParabolaAns);
                    add(lblTotalVertex);

                    btnCalc.addActionListener(this);
                    btnClear.addActionListener(this);
                    btnGraph.addActionListener(this);

                }//closes initMethod

                public void actionPerformed(ActionEvent x)
                {

                                if (x.getSource()==btnCalc)
                                {
                                	int numberA = Integer.parseInt(txtNumOne.getText());
                                    int numberB = Integer.parseInt(txtNumTwo.getText());
                                    int numberC = Integer.parseInt(txtNumThree.getText());
                                    quadCalc(numberA, numberB, numberC);
                                }//closes if

                                else if (x.getSource()==btnClear)
                                {
                                	txtNumOne.setText(" ");
                                    txtNumTwo.setText(" ");
                                    txtNumThree.setText(" ");
                                    lblAnsOne.setText("Answer A: ");
                                    lblAnsTwo.setText("Answer B: ");
                                    lblParabolaAns.setText("Parabola State: ");
                                    lblTotalVertex.setText("Vertex: ");
                                    filledVertex = false;
                                    repaint();
                                }//closes else if
                               // else if (x.getSource()==btnGraph)
                               //{
									//filledVertex = true;
									//repaint();
								//}//end else if
                }//close actionPerformed Method

                public void quadCalc (int a, int b, int c)
                {
					double ans1 = ((b*(-1)) + Math.sqrt((b*b) - (4*(a*c)))) / (2*a);
					double ans2 = ((b*(-1)) - Math.sqrt((b*b) - (4*(a*c)))) / (2*a);

					String str = "" + ans1;
					String str2 = "" + ans2;

					lblAnsOne.setText("Answer A: " + str);
					lblAnsTwo.setText("Answer B: " + str2);

					findParabola(a, b, c, ans1, ans2);
				}//end method

				public void findParabola (int a, int b, int c, double ans1, double ans2)
				{
					String answer1 = "" + ans1;
					String parabola = "";
					y = (c - (b*b) / (4*a));
					x = (b*(-1) / (2*a));
					filledVertex = true;
					repaint();

					String vertex = "(" + x + "," + y + ")";

					if (y > 0 && (!(answer1.equals("NaN"))))
					{
						parabola = "down";
					}//end if
					else if (y < 0 && (!(answer1.equals("NaN"))))
					{
						parabola = "up";
					}//end else if
					else if (y > 0 && answer1.equals("NaN"))
					{
						parabola = "up";
					}//end else if
					else if (y < 0 && answer1.equals("NaN"))
					{
						parabola = "down";
					}//end else if

					lblParabolaAns.setText("Parabola State: " + parabola);
					lblTotalVertex.setText("Vertex: " + vertex);
				}//end method

				public void paint(Graphics g)
					{
						int gridWidth = 300;
						int gridHeight = 300;
						int gridStartX = 200;
						int gridStartY = 10;

						int[][] gCPA = new int[4][2];
						gCPA[0][0] = gridStartX;
						gCPA[0][1] = gridStartY;
						gCPA[1][0] = gridStartX;
						gCPA[1][1] = gridStartY + gridWidth;
						gCPA[2][0] = gridStartX + gridHeight;
						gCPA[2][1] = gridStartY + gridWidth;
						gCPA[3][0] = gridStartX + gridHeight;
						gCPA[3][1] = gridStartY;

						g.setColor(Color.gray);

						g.drawRect(gridStartX,gridStartY,gridWidth,gridHeight);

						for(int plotX = 0; plotX < 4; plotX++)
						{
							for(int plotY = 0; plotY < 4; plotY++)
							{
								g.drawOval(gCPA[plotX][0]-5,gCPA[plotX][1]-5,10,10);
							}//end for
						}//end for

						int cellInterval = 12;
						int rowNum = gridHeight / cellInterval;
						int rowModifier = 0;

						for (int r = 0; r < rowNum; r++)
						{
							rowModifier = rowModifier + cellInterval;
							g.drawLine(gCPA[0][0],gCPA[0][1] + rowModifier,gCPA[3][0],gCPA[3][1] + rowModifier);
							g.drawLine(gCPA[0][0] + rowModifier,gCPA[0][1],gCPA[1][0] + rowModifier,gCPA[1][1]);
						}//end for

						int centerX = (((gridWidth / 2) + gCPA[0][0]) + 1);
						int centerY = (((gridHeight / 2) + gCPA[0][1]) + 1);

						String testString = centerX + ", " + centerY;

						g.fillOval(centerX,centerY,10,10);
						g.drawString(testString,10,258);


						if (filledVertex)
						{

							plotMe[0][0] = x;
							plotMe[0][1] = y;
							int plotX = 0;
							int plotY = 0;

							if (x < 0)
							{
								plotX = (centerX + (plotMe[0][0] * cellInterval));
							}//end if
							else if (x > 0)
							{
								plotX = (centerX - (plotMe[0][0] * cellInterval));
							}//end elseif

							if (y < 0)
							{
								plotY = (centerY - (plotMe[0][1] * cellInterval));
							}//end if
							else if (y > 0)
							{
								plotY = (centerY + (plotMe[0][1] * cellInterval));
							}//end elseif

							g.drawOval(plotX,plotY,10,10);
						}//end if
	}//endpaint
}//close class
*/
